<?php

// Copyright 2019 Hackware SpA <human@hackware.cl>
// "Hackware Web Services Core" is released under the MIT License terms.

namespace Hawese\Tests;

use Hawese\Core\User;
use Hawese\Core\Token;
use Laravel\Lumen\Testing\DatabaseTransactions;

class TokenTest extends TestCase
{
    use DatabaseTransactions;

    public function testGenerate()
    {
        $user = new User(['uid' => 'user']);
        $user->insert();

        $token = Token::generate(Token::HUMAN, $user->uid);
        $this->assertInstanceOf(Token::class, $token);

        $tokenFound = Token::find($token->key);
        $this->assertSame($token->key, $tokenFound->key);
        $this->assertNotSame($token->secret, $tokenFound->secret);
    }

    public function testToString()
    {
        $token = new Token(['key' => 'a_token']);
        $this->assertSame('a_token', (string) $token);
    }
}
